<?php
function forTags($array,$tag,$value,$select){
	if(is_array($array)){
		$valType = is_array($value) ? 'array' : 'single';
		$i = $tags = '';
		foreach($array as $val=>$txt){
			if(($valType = 'array' && in_array($val,$value)) || ($valType = 'single' && $value == $val)){
				$tags .= sprintf($tag,$i++,$val,$txt,$select);
			}else{
				$tags .= sprintf($tag,$i++,$val,$txt,'');
			}
		}
		return $tags;
	}
	return false;
}
function array_delete($array,$key_to_be_deleted){
	if(is_string($key_to_be_deleted)){
		if(!array_key_exists($key_to_be_deleted,$array)){
			return false;
		}
		foreach($array as $key=>$value){
			if($key == $key_to_be_deleted){
				unset($array[$key]);
			}
		}
	}else if(is_array($key_to_be_deleted)){
		foreach($key_to_be_deleted as $del){
			$array = array_delete($array,$del);
		}
	}
	return $array;
}
function secure_DB_input($string){
	if(!get_magic_quotes_gpc()){
		$string = addslashes($string);
	}else{
		$string = mysql_real_escape_string($string);
	}
	return $string;
}
function mysql2array($array){
	if(is_array($array)){
		$QUERY_STR = mb_convert_encoding(trim($array['Q']).' '.trim($array['C']),'UTF-8');
		$QUERY_STR = secure_DB_input($QUERY_STR);
		$RESULT = @mysql_query($QUERY_STR);
		if(@mysql_num_rows($RESULT) > 0){
			while($row = mysql_fetch_assoc($RESULT)){
				$ARRAY[$row[$array['K']]] = $row[$array['T']];
			}
			return $ARRAY;
		}
	}
	return false;
}
?>